﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BusinessLogicLayer;

namespace UserInterfaceLayer.User
{
    public partial class DayView : System.Web.UI.Page
    {
        DateTime Current;

        protected void Page_Load(object sender, EventArgs e)
        {
            PersianCalendar pCalendar = new PersianCalendar();
            string strCurrent = Request.QueryString["d"];
            if (!PersianDateTimeExtension.TryParseHijriSolar(strCurrent, out Current))
                Response.Redirect("DayView.aspx?d=" + DateTime.Now.ToShortHijriSolarDateString());
            lblCurrent.Text = Current.ToShortHijriSolarDateString() + " , " + Current.ToShortHijriLunarDateString();

            DataAccessLayer.linqDatabaseDataContext db = new DataAccessLayer.linqDatabaseDataContext();
            List<BusinessLogicLayer.DataObject.Floor> Floors = BusinessLogicLayer.DataObject.Floor.Convert(DataAccessLayer.Floor.ToList(db));
            Floors.Reverse();
            foreach (BusinessLogicLayer.DataObject.Floor ThisFloor in Floors)
                ThisFloor.ReserveRooms = BusinessLogicLayer.DataObject.ReserveRoom.Convert(ThisFloor.dRooms, Current, Current.AddDays(1).AddMilliseconds(-1), db);
            lvFloors.DataSource = Floors;
            lvFloors.DataBind();
        }

        protected void btnPrev_Click(object sender, EventArgs e)
        {
            Response.Redirect("DayView.aspx?d=" + Current.AddDays(-1).ToShortHijriSolarDateString());
        }

        protected void btnNext_Click(object sender, EventArgs e)
        {
            Response.Redirect("DayView.aspx?d=" + Current.AddDays(1).ToShortHijriSolarDateString());
        }
    }
}